'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 支付
 * @author sundbcn@gmail.com (sun debing)
 */

var modelUtil = require('../util/modelUtil');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var paySchema = require('../schemas/paySchema');
var Pay = mongoConnector().model('Pay');

/**
 * 添加一个支付记录
 */
module.exports.getByRoleId = function (role_id, cb) {
    modelUtil.getByRoleId(Pay, role_id, function (err, pay_model) {
        if (!!err) {
            console.error(err);
            return cb(err);
        }
        if (pay_model.month_leave_day > 0) {
            // 过渡转换处理，将剩余天数转到月效期结束时间
            pay_model.addMonthDay(pay_model.month_leave_day);
            pay_model.month_leave_day = 0;
        }
        cb(err, pay_model);
    });
};
